package top.hmtools.jsCss.yui;

import org.mozilla.javascript.ErrorReporter;
import org.mozilla.javascript.EvaluatorException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * yui 压缩工具警告、错误日志打印工具
 * @author HyboWork
 *
 */
public class YuiLoggerErrorReporter implements ErrorReporter {

	private final Logger logger = LoggerFactory.getLogger(YuiLoggerErrorReporter.class);
	
	@Override
	public void warning(String message, String sourceName, int line, String lineSource, int lineOffset) {
		this.logger.warn("{}：{}",sourceName,lineSource);
		if(line<0){
			this.logger.warn("yui压缩工具警告：{}",message);
		}else{
			this.logger.warn("yui压缩工具警告：line：{}，lineOffset：{}，message：{}",line,lineOffset,message);
		}
	}

	@Override
	public void error(String message, String sourceName, int line, String lineSource, int lineOffset) {
		this.logger.error("{}：{}",sourceName,lineSource);
		if(line<0){
			this.logger.error("yui压缩工具警告：{}",message);
		}else{
			this.logger.error("yui压缩工具警告：line：{}，lineOffset：{}，message：{}",line,lineOffset,message);
		}
	}

	@Override
	public EvaluatorException runtimeError(String message, String sourceName, int line, String lineSource,
			int lineOffset) {
		error(message, sourceName, line, lineSource, lineOffset);
		return new EvaluatorException(message);
	}
}
